// pages/index/search/search_jg/search_jg.js
var id = ''
var url = wx.getStorageSync('url')
var userId = wx.getStorageSync('userId')
var openid = wx.getStorageSync('openid')
var shopid = wx.getStorageSync('shopid')
var time_ss = wx.getStorageSync('time_ss')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentTab:1
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var shopid = wx.getStorageSync('shopid')
    var userId = wx.getStorageSync('userId')
    var openid = wx.getStorageSync('openid')
    var time_ss = wx.getStorageSync('time_ss')
    id = options.id
    console.log(id)
    var that = this
    // 搜索
    wx.request({
      url: url+'gateWare/mpSearch',
      data: {
        "platform": 2,
        "privId": "0000",
        "resId": "0000",
        "sendTime": time_ss,
        "seq": "232312313",
        "shopId": shopid,
        "source": 1,
        "sysVer": "0.0.1",
        "type": 1,
        "userId": userId,
        "userType": 1,
        "content": {
          "shopId": shopid,
          "searchKey": id,
          "sort":1
        }
      },
      method: "POST",
      header: { "Content-Type": "application/JSON" },
      success: function (e) {
        var data = e.data.content
        console.log(e)
        that.setData({
          banler: data
        })
      }
    })
  },
  inputTyping:function(e){
    var url = wx.getStorageSync('url')
    var shopid = wx.getStorageSync('shopid')
    var userId = wx.getStorageSync('userId')
    var openid = wx.getStorageSync('openid')
    var time_ss = wx.getStorageSync('time_ss')
    var that = this ;
    var id = e.detail.value;
    that.setData({
      value:id,
      currentTab: 1
    })
    wx.request({
      url: url + 'gateWare/mpSearch',
      data: {
        "platform": 2,
        "privId": "0000",
        "resId": "0000",
        "sendTime": time_ss,
        "seq": "232312313",
        "shopId": shopid,
        "source": 1,
        "sysVer": "0.0.1",
        "type": 1,
        "userId": userId,
        "userType": 1,
        "content": {
          "shopId": shopid,
          "searchKey": id,
          "sort": 1
        }
      },
      method: "POST",
      header: { "Content-Type": "application/JSON" },
      success: function (e) {
        console.log(e)
        var data = e.data.content
        that.setData({
          banler: data,
        })
      }
    })
  },
  switchbind:function(e){
    var url = wx.getStorageSync('url')
    var shopid = wx.getStorageSync('shopid')
    var userId = wx.getStorageSync('userId')
    var openid = wx.getStorageSync('openid')
    var time_ss = wx.getStorageSync('time_ss')
    var id = this.data.value
    var i = e.currentTarget.dataset.current
    var  that = this;
    that.setData({
      currentTab: e.currentTarget.dataset.current
    })
    wx.request({
      url: url + 'gateWare/mpSearch',
      data: {
        "platform": 2,
        "privId": "0000",
        "resId": "0000",
        "sendTime": time_ss,
        "seq": "232312313",
        "shopId": shopid,
        "source": 1,
        "sysVer": "0.0.1",
        "type": 1,
        "userId": userId,
        "userType": 1,
        "content": {
          "shopId": shopid,
          "searchKey": id,
          "sort": i
        }
      },
      method: "POST",
      header: { "Content-Type": "application/JSON" },
      success: function (e) {
        console.log(e)
        var data = e.data.content
        if(i==1){
          that.setData({
            banler: data,
          })
        }
        if(i==2){
          that.setData({
            banler1: data,
          })
        }
        if(i==3){
          that.setData({
            banler2: data,
          })
        }
      }
    })
  },
  // 生成订单
  goto_OrderAddress:function(e){  
    console.log(e)
    var wareId = e.currentTarget.dataset.wareid
    var activityId = e.currentTarget.dataset.activityid
    var tag = e.currentTarget.dataset.tag
    wx.navigateTo({
      url: '../../../Order/OrderAddress/OrderAddress?wareId='+wareId+'&activityId='+activityId+'&tag='+tag,
    })
  },
  goto_xingqing:function(e){
    var wareId = e.currentTarget.dataset.wareid
    var activityId = e.currentTarget.dataset.activityid
    var tag = e.currentTarget.dataset.tag
    if (tag==1){
      wx.navigateTo({
        url: '../../MeteorFall/Star_details/Star_details?wareId=' + wareId + '&activityId=' + activityId + '&tag=' + tag,
      })
    }else{
      wx.navigateTo({
        url: '../../BeautyKilling/kill_details/kill_details?wareId=' + wareId + '&activityId=' + activityId + '&tag=' + tag,
      })
    }
    
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    that.setData({
      value: id
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})